package fun._6742.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import fun._6742.request.CreateBannerRequest;
import fun._6742.service.AdminBannerService;

import javax.annotation.Resource;

@Api(tags = "轮播图")
@RestController
@RequestMapping("api/admin/banner/v1")
public class AdminBannerController {
    @Resource
    AdminBannerService adminBannerService;


    @ApiOperation(value = "轮播图新增", notes = "轮播图图片传base64字符串")
    @PostMapping("/")
    public void newProduct(@ApiParam(value = "轮播图信息") @RequestBody CreateBannerRequest createBannerRequest) {
        adminBannerService.createBanner(createBannerRequest);
    }

    @ApiOperation(value = "轮播图删除")
    @DeleteMapping("/{id}")
    public void deleteProduct(@PathVariable(value = "id") long id) {
        adminBannerService.deleteBanner(id);
    }

    @ApiOperation(value = "轮播图查找")
    @GetMapping("/")
    public Object pageProduct(
            @ApiParam(value = "轮播图id") @RequestParam(value = "id", defaultValue = "-1") long id,
            @ApiParam(value = "当前页") @RequestParam(value = "page", defaultValue = "1") int page,
            @ApiParam(value = "每页显示条数") @RequestParam(value = "size", defaultValue = "10") int size) {
        if (id > 0) {
            return adminBannerService.findOne(id);
        } else {
            return adminBannerService.findPage(page, size);
        }
    }
}
